/**
 * 
 */
package se.thoka.twt.client.utils.validation;

import java.util.List;

import se.thoka.twt.client.utils.UniqueList;

/**
 * @author Thobias Karlsson, Thoka
 * @since 9 jan 2010
 */
public class ValidationBundle implements Validation {

	private List<Validation> validations;
	private String description;
	
	/**
	 * Creates a new instance of {@link ValidationBundle}.
	 * @param validation The validations to start with
	 */
	public ValidationBundle(Validation... validation) {
		validations = new UniqueList<Validation>();
		for (Validation v : validation) {
			validations.add(v);
		}
	}

	@Override
	public String getDescription() {
		return description;
	}

	@Override
	public boolean validate(String value) {
		boolean valid = true;
		for (Validation v : validations) {
			if (!v.validate(value)) {
				description = v.getDescription();
				valid = false;
				break;
			}
		}
		return valid;
	}
	
}
